package com.niiwoo.civet.trade.service.dubbo.loan.core;

import com.niiwoo.civet.trade.dao.entity.Project;
import com.niiwoo.civet.trade.enums.ProjectFromSourceEnum;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Service;

@Slf4j
@Service
public class StandardSpeedLoanFactory implements ISpeedLoanFactory {

    @Autowired
    private ApplicationContext applicationContext;

    @Override
    public ISpeedLoanService adaptive(Project project) {
        ISpeedLoanService service = null;

        if (project.getType().equals(com.niiwoo.civet.trade.enums.ProjectTypeEnum.CARD_NIU_LOAN.getValue())) {
            service = applicationContext.getBean(CardNiuSpeedLoanServiceImpl.class);
        } else if (project.getType().equals(com.niiwoo.civet.trade.enums.ProjectTypeEnum.ORG_SPEEDLOAN_NEW.getValue())
                || project.getType().equals(com.niiwoo.civet.trade.enums.ProjectTypeEnum.DECORATION_LOAN.getValue())) {
            service = applicationContext.getBean(OrgSpeedLoanServiceImpl.class);
        } else if (project.getType().equals(com.niiwoo.civet.trade.enums.ProjectTypeEnum.PERSONAL_SPEEDLOAN.getValue())) {
            if (ProjectFromSourceEnum.R360.getType().equals(project.getFromSource())) {
                service = applicationContext.getBean(R360SpeedLoanServiceImpl.class);
            }
        } else {
            service = applicationContext.getBean(StandardSpeedLoanServiceImpl.class);
        }
        
        return service;
    }
}
